package com.pace.ribbon.endpoint;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 自定义端点类，实现查看当前用户的信息
 */

@Component
@Endpoint(id = "user")
public class MyUserEndponit extends AbstractHealthIndicator {

    /**
     * 自己实现的
     * @return
     */
    @ReadOperation
    public List<Map<String,Object>> myHealth(){
        List<Map<String,Object>> list = new ArrayList<>();
        Map<String,Object> map  = new HashMap<>();
        map.put("userId","1");
        map.put("userName","admin");
        list.add(map);
        return list;
    }

    /**
     * 自定义规则用以判断应用的状态是否监控，通过继承AbstarctHealthIndicator实现
     * @param builder
     * @throws Exception
     */
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        builder.up().withDetail("status",true);
//        builder.down().withDetail("status",false);
    }
}
